<template>
  <div>
    <div>
      <el-form :inline="true" :model="selectUser" class="demo-form-inline">
        <el-form-item label="用户名">
          <el-input v-model="selectUser.username"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="selectByUsername()">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="postMaMa">
      <el-table
          size="small"
          stripe
          border
          :data="allManager"
          style="width: 80%">
        <!--        prop为data数组的列名-->
<!--        <el-table-column-->
<!--            prop="id"-->
<!--            label="名字"-->
<!--            width="180">-->
<!--        </el-table-column>-->
        <el-table-column
            prop="username"
            label="名字"
            width="250">
        </el-table-column>
        <el-table-column
            prop="num"
            label="登录次数"
            width="180">
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
                size="mini"
                type="success"
                @click="updateUserAuth(scope.row)">升级权限
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div>
        <el-pagination
            layout="total,prev,pager,next,jumper"
            :page-size="page.size"
            :total="page.total"
            :current-page="page.curren"
            @current-change="pagechange"
        >
        </el-pagination>
      </div>
    </div>
  </div>

</template>

<script>
export default {
  name: 'Manager',
  data() {
    return {
      page :{
        size: 0,
        current: 1,
        total: 0,
      },
      selectUser:{
        username: ''
      },
      addManager: {
        id: 0,
        username: '',
        password: '',
        num: 0,
        gmtCreate: '',
        gmtModified:'',
        deleted:0,
        //想要添加的管理员名称
      },
      allManager: [],//列表的数组
      dialogVisible: false,//弹出框
      // multipleSelection: [],

      updatePos: {//编辑内容
        username: '',
        password: '',
        state: 0,
        loginNum: 0
      },
      delManager: {
        username: '',
        password: '',
        state: 0,
        loginNum: 0
      },
    }
  },
methods: {
        init() {
          this.getRequest('/manager/all/'+this.page.current).then(resp => {//put改get不报错，但无法更改
            this.allManager=resp.data.records
            this.page.size=resp.data.size
            this.page.total=resp.data.total
            this.page.current=resp.data.current

          })
        },

        pagechange(val){
          this.page.current=val
          this.init()
        },

        selectByUsername(){
          this.postRequest('/manager/select?username='+this.selectUser.username).then(resp => {
                if (resp) {
                  this.allManager = resp;
          }
          })
        },

        updateUserAuth(data) {//权限升级
          this.postRequest('/manager/roles?id=' + data.id).then(resp => {
            if (resp){
              this.$message.success(resp.message);
              this.init();
            }
          })

        },

},
mounted() {
        this.init();
}


}
</script>

<style scoped>
.addPosInput {
  width: 300px;
  margin-right: 8px;
}

.postMaMa {
  margin-top: 10px;
}

.updatePosInput {
  width: 280px;
  margin-left: 8px;
}
</style>
